package com.itheima.dao;

import com.itheima.domain.Answer;
import com.itheima.domain.Question;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AnswerDao {
    @Insert("insert into answer values (null, #{content}, #{qid}, #{uid}, #{is_accept}, #{likes}, #{createtime})")
    void save(Answer answer);

    @Update("update answer set content = #{content}, is_accept = #{is_accept}, likes = #{likes} where aid = #{aid}")
    int update(Answer answer);

    @Delete("delete from answer where aid = #{aid}")
    int delete(Integer aid);

    @Select("select * from answer where aid = #{aid}")
    Answer getById(Integer aid);

    @Select("select * from answer ")
    List<Answer> getAll();

    @Select("select * from answer where qid = #{qid}")
    List<Answer> getByQid(Integer qid);

    @Update("update answer set  likes = likes + 1 where aid = #{aid}")
    int addlike(Integer aid);
    @Update("update answer set  likes = likes - 1 where aid = #{aid}")
    int cancellike(Integer aid);

    @Select("select count(*) from answer where qid = #{qid}")
    int answerCount(Integer qid);
}
